package com.smartcommunity.service.fullSearch.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smartcommunity.bean.model.Pager;
import com.smartcommunity.dao.fullSearch.SearchHistoryDao;
import com.smartcommunity.entity.fullSearch.SearchHistory;
import com.smartcommunity.service.fullSearch.SearchHistoryService;

/**
 * @ClassName: SearchHistoryServiceImpl
 * @Description: 全息档案搜索历史业务层实现类
 * @author: yangyi
 * @Date: 2020/6/30 17:45
 * @Company:
 */
@Service
public class SearchHistoryServiceImpl implements SearchHistoryService {

	@Autowired
	private SearchHistoryDao dao;
	
	/**
	 * 新增搜索历史
	 */
	@Override
	public void saveSearchHistory(SearchHistory searchHistory) {
		dao.saveSearchHistory(searchHistory);
	}

	/**
	 * 分页查找用户搜索历史
	 */
	@Override
	public Pager<SearchHistory> listUserHistory(Integer pageNumber, Integer pageSize, Integer userId) {
		Integer total = dao.countUserHistory(userId);
		List<SearchHistory> rows = dao.listUserHistory((pageNumber-1)*pageSize, pageSize, userId);
		return new Pager<>(pageNumber, pageSize, total, rows);
	}

	/**
	 * 删除用户搜索历史
	 */
	@Override
	public void delUserHistory(Integer userId) {
		SearchHistory searchHistory = new SearchHistory();
		searchHistory.setUserId(userId);
		dao.delSearchHistory(searchHistory);
	}

	/**
	 * 删除单条搜索历史
	 */
	@Override
	public void delHistoryById(Long id) {
		SearchHistory searchHistory = new SearchHistory();
		searchHistory.setId(id);
		dao.delSearchHistory(searchHistory);
	}

}
